package xmlS
{
	import main.XMLLoaderBase;
	
	public class NavigationNewXMLLoader extends XMLLoaderBase
	{
		private var _dataDic:Object = {};
		private var _key:String;
		private var _callBack:Function;
		public function NavigationNewXMLLoader()
		{
			super();
		}
		
		public function init(keyStr:String,callBack:Function):void
		{
			if(_dataDic[_key] != null)
			{
				if(callBack != null)
				{
					callBack();
				}
			}
			_key = keyStr;
			_callBack = callBack;
			super.loadXml(keyStr,loadXMLComplete,null);
		}
		
		private function loadXMLComplete(value:XML):void
		{
			var info:Object = {};//存储解析出来的数据		
			var xmlList:XMLList;
			xmlList = value.child("base");
			var baseInfo:Object = {};
			for(var i:int = 0;i < xmlList.length();i++)
			{
				baseInfo.name = xmlList[i].@name;
				baseInfo.desc = xmlList[i].@desc;
			}
			info.base = baseInfo;
			
			xmlList = value.child("path");
			info.speedPath = {path:String(xmlList[0].speedPath).split(","),time:String(xmlList[0].speedPath.@time).split(","),desc:String(xmlList[0].speedPath.@desc)};
			info.normalPath = {path:String(xmlList[0].normalPath).split(","),time:String(xmlList[0].normalPath.@time).split(","),desc:String(xmlList[0].normalPath.@desc)};
			info.carPath = {path:String(xmlList[0].carPath).split(","),time:String(xmlList[0].carPath.@time).split(","),desc:String(xmlList[0].carPath.@desc)};
			
			xmlList = value.child("viewSpots");
//			xmlList = xmlList[0].child("viewSpot");
			var spotList:Array = [];
			xmlList = xmlList[0].child("viewSpot");
			for(i = 0;i<xmlList.length();i++)
			{
				var spot:Object = {};
				spot.name = xmlList[i].@name;
				spot.id = int(xmlList[i].@id);
				spot.icon = xmlList[i].@icon;
				spot.desc = xmlList[i].@desc;
				spot.mp3 = xmlList[i].@mp3;
				spot.openStartTime = xmlList[i].@openStartTime;
				spot.openEndTime = xmlList[i].@openEndTime;
				spot.posX = xmlList[i].@posX;
				spot.posY = xmlList[i].@posY;
				spot.gpsX = Number(xmlList[i].@gpsX);
				spot.gpsY = Number(xmlList[i].@gpsY);
				spot.offset = Number(xmlList[i].@offset);
				spot.star = xmlList[i].@star;
				spotList.push(spot);
			}
			info.viewspots = spotList;
			
			xmlList = value.child("wcs");
			xmlList = xmlList[0].child("wc");
			var wcList:Array = [];
			for(i = 0;i<xmlList.length();i++)
			{
				var wc:Object = {};
				wc.posX = xmlList[i].@posX;
				wc.posY = xmlList[i].@posY;
				wcList.push(wc);
			}
			info.wcs = wcList;
			
			_dataDic[_key] = info;
			
			if(_callBack != null)
			{
				_callBack();
			}
		}
		
		public function getData(key:String):Object
		{
			return _dataDic[key];
		}
		
	}
}